package wo.esys.dto;

import java.util.ArrayList;
import java.util.List;

import wo.common.util.WoUtil;
import wo.esys.po.Menu;

public class MenuDto {

	/**
	 * ID
	 */
	private String id;

	/**
	 * 名称
	 */
	private String name;

	/**
	 * 编号
	 */
	private String no;

	/**
	 * 图标
	 */
	private String icon;

	/**
	 * URL
	 */
	private String url;

	/**
	 * 上级菜单id.
	 */
	private String parentId = "";

	/**
	 * 上级菜单名称
	 */
	private String parentName = "";

	public MenuDto(Menu m) {
		this.id = m.getId();
		this.icon = m.getIcon();
		this.name = m.getName();
		this.no = m.getNo();
		this.url = m.getUrl();
		if (m.getParent() != null) {
			this.parentId = m.getParent().getId();
			this.parentName = m.getParent().getName();
		}
		
	}

	public MenuDto() {
		super();
		// TODO Auto-generated constructor stub
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public String getParentName() {
		return parentName;
	}

	public void setParentName(String parentName) {
		this.parentName = parentName;
	}
	
	public Menu createPO () {
		Menu parent = null;
		if (!WoUtil.isEmpty(parentId)) {
			parent = new Menu ();
			parent.setId(parentId);
		}
		Menu m = new Menu(id, name, no, icon, url, parent);
		return m;
	}
	
	/**
     * @param pos
     * @return
     */
    public static List<MenuDto> getDtos (List<Menu> pos) {
        List<MenuDto> dtos = new ArrayList<MenuDto>();
        for (Menu po : pos) {
            dtos.add(new MenuDto(po));
        }
        return dtos;
    }
}
